package com.edu.controller.food;

import com.edu.entity.Food;
import com.edu.entity.FoodType;
import com.edu.service.food.FoodService;
import com.edu.service.food.FoodServiceImpl;
import com.edu.service.foodtype.FoodTypeService;
import com.edu.service.foodtype.FoodTypeServiceImpl;
import com.edu.utils.ParamFormat;
import com.edu.utils.ResponseBody;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @Author ZCN
 * @Date 2021/11/13 21:44
 * @Version 1.0
 **/
@WebServlet("/food/delete")
public class UnlineServlet extends HttpServlet {

    private FoodService foodService = new FoodServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            // utf-8格式化
            ParamFormat.format(req,resp);
            Map<String, String[]> map = req.getParameterMap();
            Food food = new Food();
            // 将map对象转换成java对象
            BeanUtils.populate(food,map);
            foodService.delete(food.getId());
            ResponseBody.success(resp,"success",0L,null);
        } catch (Exception e) {
            e.printStackTrace();
            ResponseBody.failure(resp,e.getMessage());
        }
    }
}
